<?php
/**
 * author: JiangJun
 * CreateTime:2021/8/11 11:06 上午
 */

use Aws\Exception\AwsException;
use Aws\Sqs\SqsClient;

require './vendor/autoload.php';


$client = new SqsClient([
    'region' => 'us-west-2',
    'version' => '2012-11-05'
]);

$queueUrl = "https://sqs.us-west-2.amazonaws.com/863376839233/test.fifo";


try {
    $result = $client->receiveMessage(array(
        'AttributeNames' => ['SentTimestamp'],
        'MaxNumberOfMessages' => 10,//1到10之间
        'MessageAttributeNames' => ['All'],
        'QueueUrl' => $queueUrl, // REQUIRED
        'WaitTimeSeconds' => 5,//大于0，就是长轮询，最长20秒
    ));
    $msg=$result->get('Messages');
    if(empty($msg)){
        echo '没有消息' . PHP_EOL;die;
    }
    var_dump($msg);
    //print_r($msg);//是一个二维数组,每个元素,就是一条消息
    print_r(array_column($msg,'Body'));
} catch (AwsException $e) {
    error_log($e->getMessage());
}